package com.xuecheng.content.api;

import cn.hutool.core.bean.BeanUtil;
import com.xuecheng.base.exception.XueChengPlusException;
import com.xuecheng.content.model.dto.CourseTeacherDto;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shiminghui
 * @date 2024/8/4 13:19
 * @description: TODO
 */
@RestController
@Slf4j
@Api("师资管理相关接口")
@RequestMapping
@RequiredArgsConstructor
public class CourseTeacherController {

    private final CourseTeacherService courseTeacherService;

    @GetMapping("courseTeacher/list/{courseId}")
    @ApiOperation("根据课程id查询师资信息")
    public List<CourseTeacherDto> queryCourseTeacher(@PathVariable Long courseId) {
        log.info("查询师资信息的课程id为{}", courseId);
        List<CourseTeacherDto> list = courseTeacherService.getByCourseId(courseId);
        return list;
    }

    @PostMapping("/courseTeacher")
    @ApiOperation("保存师资信息")
    public CourseTeacherDto addCourseTeacher(@RequestBody CourseTeacherDto courseTeacherDto) {
        log.info("保存师资信息参数{}", courseTeacherDto);
        CourseTeacherDto courseTeacher = courseTeacherService.saveCourseTeacher(courseTeacherDto);
        return courseTeacher;
    }

    @ApiOperation("删除师资信息")
    @DeleteMapping("/courseTeacher/course/{courseId}/{id}")
    public void deleteCourseTeacher(@PathVariable Long courseId, @PathVariable Long id) {
        log.info("删除师资信息参数,课程id{},教师id{}", courseId, id);
        courseTeacherService.deleteCourseTeacherById(courseId, id);
    }

}
